package archer.application.core.service.system;

import archer.application.core.entity.system.Suspicious;
import archer.application.core.service.BaseService;
import archer.framework.security.analog.AnalogLoginProcessor;
import archer.framework.security.analog.AnalogUser;
import archer.framework.security.netpolice.SuspiciousEvent;
import archer.framework.security.utils.AnalogUtils;
import jodd.bean.BeanCopy;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author christ
 * @date 2016/8/18
 */
@Component
public class NetPolice extends BaseService implements archer.framework.security.netpolice.NetPolice {

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void report(final SuspiciousEvent event) {

        if (isNotEmpty(event)) {

            AnalogUtils.process(AnalogUser.ANALOG_USER_SYSTEM, new AnalogLoginProcessor() {

                @Override
                public void process() {
                    Suspicious suspicious = new Suspicious();
                    BeanCopy.fromBean(event).toBean(suspicious).copy();
                    suspicious.store();
                }
            });
        }
    }
}
